<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>会员资料</title>
    <link href="../../rs/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="../../rs/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="../../rs/plugins/bootstrap_tab/css/bootstrap-table.css" rel="stylesheet">
    <link href="../../rs/css/animate.min.css" rel="stylesheet">
    <link href="../../rs/plugins/bootstrap_tab/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="../../rs/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <link href="../../rs/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <link href="../../rs/plugins/bootstrap-editable/css/bootstrap-editable.css" rel="stylesheet">
    <?php
         require_once('login.php');
    ?>
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
       <div class="ibox-content">
            <div class="row" style="padding-bottom:10px">
                <div class="col-sm-8" >
                    <button style="  margin-right:5px"  id="remove" class="btn btn-danger" disabled>
                        <i class="glyphicon glyphicon-trash"></i>
                    </button>
                    <button onclick="add_btn()" style=" margin-left:5px;" class="btn ">
                        <i class="glyphicon  glyphicon-plus"></i> 新增
                    </button>
                     
                      
                    <div class="input-group" style=" display: inline-block;margin-left:5px;">
                        <button  type="button" class="btn" style="border-radius: 2px 0px 0px 2px;">门店</button>
                        <select class="form-control"  id="m_ck"  style="width:300px;float:right;"></select>
                    </div>
                </div>


                <div class="col-sm-4">
                    <div class="input-group" style="width:300px;float:right;"  id="key">
                        <input style="height:34px;" id="searchtext" type="text" placeholder="请输入关键词" class="input-sm form-control">
                        <span class="input-group-btn">
                          <button onclick="do_search()" style="height:34px;" type="button" class="btn btn-sm "> 查找</button>
                        </span>
                    </div>
                </div>
            </div>
           <table id="table"
               data-toggle="table"
               
            <thead>
            <tr>
                <th data-field="id" data-formatter="ID: %s">ID</th>
                <th data-field="name" data-formatter="nameFormatter">Item Name</th>
                <th data-field="price" data-formatter="priceFormatter">Item Price</th>
            </tr>
            </thead>
        </table>
        <!-- End Example Card View -->
    </div>
</div>
</div>
<!-- End Panel Other -->


<div style="display: none" id="open_edit">
    <form id="edit_from">
        <div class="input-group"   style="padding: 20px 20px 10px 20px;">
            <div class="input-group-btn">
                <button type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown">卡号</button>
            </div>
            <input type="text" class="form-control "  name="cuid" >
        </div>
        <div class="input-group"   style="padding: 0px 20px 10px 20px;">
            <div class="input-group-btn">
                <button type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown">姓名</button>
            </div>
            <input type="text" class="form-control "   name="cuname1">
        </div>

        <div class="input-group" style="padding: 0px 20px 10px 20px;">
            <div class="input-group-btn">
                <button  type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown">性别</button>
            </div>
            <select class="form-control"   name="cusex">
                <option >男</option>
                <option >女</option>
            </select>
        </div>
        <div class="input-group"   style="padding: 0px 20px 10px 20px;">
            <div class="input-group-btn">
                <button type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown">生日</button>
            </div>
            <input style="min-width: 100%;" type="text" class="form-control layer-date" placeholder="请选择日期" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})" name="srrq">
            <!--<input type="text" class="form-control "   name="srrq">-->
        </div>
        <div class="input-group"   style="padding: 0px 20px 10px 20px;">
            <div class="input-group-btn">
                <button type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown">手机</button>
            </div>
            <input type="text" class="form-control "   name="cumomile">
        </div>
        <div class="input-group"   style="padding: 0px 20px 10px 20px;">
            <div class="input-group-btn">
                <button type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown">电话</button>
            </div>
            <input type="text" class="form-control "   name="cutel">
        </div>
        <div class="input-group"   style="padding: 0px 20px 10px 20px;">
            <div class="input-group-btn">
                <button type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown">地址</button>
            </div>
            <input type="text" class="form-control "   name="cuadd">
        </div>
        <div class="input-group"   style="padding: 0px 20px 10px 20px;">
            <div class="input-group-btn">
                <button type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown">邮编</button>
            </div>
            <input type="text" class="form-control "   name="cupost">
        </div>
        <div class="input-group"   style="padding: 0px 20px 10px 20px;">
            <div class="input-group-btn">
                <button type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown">Mail</button>
            </div>
            <input type="text" class="form-control "   name="cumail">
        </div>
        <div class="input-group"   style="padding: 0px 20px 10px 20px;">
            <div class="input-group-btn">
                <button type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown">折扣</button>
            </div>
            <input type="text" class="form-control "   name="cudiscount">
        </div>
        <div class="form-group"   >
            <div class="col-sm-11" style="padding: 10px 20px 10px 20px;">
                <label class="checkbox-inline i-checks"><input type="checkbox"    name="overdraft">可透支</label>
                <label class="checkbox-inline i-checks"><input type="checkbox"    name="sfjf">可积分</label>
            </div>
        </div>
        <div style="position: absolute;width:100%;bottom:0px;padding: 0px 20px 10px 20px;">
            <button type="reset" id="reset" style="display:none;">reset</button>
            <button type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown"
                    style="background-color: #e2e2e2;" onclick="layer.closeAll()">返回
            </button>
            <button type="button" class="btn btn-white dropdown-toggle " data-toggle="dropdown"
                    style="background-color: #f54141;color: white;float: right" id="save_do">保存
            </button>
        </div>
    </form>
</div>

<script src="../../rs/js/jquery.min.js"></script>
<script src="../../rs/js/bootstrap.js"></script>
<script src="../../rs/plugins/bootstrap_tab/js/bootstrap-table.min.js"></script>
<script src="../../rs/plugins/bootstrap_tab/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="../../rs/plugins/datapicker/bootstrap-datepicker.js"></script>
<script src="../../rs/js/jquery.cookie.js"></script>
<script src="../../rs/js/common_qj.js"></script>
<script src="../../rs/plugins/layer/layer.min.js"></script>
<script src="../../rs/plugins/bootstrap-editable/js/bootstrap-editable.js"></script>
<script src="../../rs/plugins/bootstrap_tab/js/plugins/iCheck/icheck.min.js"></script>
<script src="../../rs/plugins/bootstrap_tab/js/plugins/layer/laydate/laydate.js"></script>
<script src="../../rs/plugins/bootstrap-editable/js/bootstrap-table-editable.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",})});




    var sign = URLencode($.cookie('sign'));
    var $table = $('#table');
    var $remove = $('#remove');
    var mydata;
    $(function(){

        $('#table').bootstrapTable({
            columns: [
                {
                    field: 'state',
                    checkbox: true
                },

                {
                    field: 'cuid',
                    title: '客户编号',
                    align: 'left',
                    formatter:"actionFormatter"
                },
                {
                    field: 'cuname1',
                    align: 'left',

                    title: '客户名称'
                },
                {
                    field: 'cusex',
                    align: 'center',
                    title: '性别',

                },
                {
                    field: 'srrq',
                    align: 'center',
                    title: '生日',

                },
                {
                    field: 'jf',
                    align: 'center',
                    title: '积分',

                },
                {
                    field: 'cudiscount',
                    align: 'center',
                    title: '折扣',

                },


                {
                    field: 'sum1',
                    align: 'left',
                    title: '卡余额'
                },
                {
                    field: 'custate',
                    align: 'center',
                    title: '状态',

                }
            ],
            singleSelect: true,
            pagination: true,
            pageSize:20
        });
        f_sheard();
    });


    function f_sheard() {

        layer.load(2);
        $.ajax({
            type: "post",
            url:G_url+'cacu/see_page?sign='+sign,
            data:'sign='+sign,
            dataType: "json",
            success: function (aftdata) {
                mydata=aftdata;

                layer.closeAll('loading');
                $('#table').bootstrapTable('load', aftdata.data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
            }
        });
    }


    $(function () {
        <!-- 删除操作 -->
        $table.on('check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table', function () {
            $remove.prop('disabled', !$table.bootstrapTable('getSelections').length);
        });
        $remove.click(function () {
            var cuids = $.map($table.bootstrapTable('getSelections'), function (row) {
                return row.cuid;
            });
            $.ajax({
                type: "post",
                url: G_url+'cacu/del/?sign='+sign,
                data:"&cuid=" +cuids,
                dataType: "json",
                success: function (result) {
                    if (result.ok) {
                        layer.closeAll();
                        $table.bootstrapTable('remove', {
                            field: 'cuid',
                            values: cuids
                        });
                        layer.msg(result.msg);

                    } else {
                        layer.msg(result.msg);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    //alert(errorThrown);
                }
            });



            $remove.prop('disabled', true);
        });
        <!-- 删除操作 -->

    });


    <!--新增操作-->
    function add_btn(){
        open_modal();
    }
    function open_modal(){
        $("#open_edit").show();
        $("input[name='bh']").attr("disabled",false);
        $('#reset').click();
        layer.open({
            title: "新增",
            type: 1,

            offset: 'rb',
            area: ['40%', '100%'], //宽高
            shadeClose: true,
            content: $('#edit_from')
        });
    }
    <!--新增操作-->

    <!--保存操作-->
    var rid;
    var index;
    $("#save_do").on("click",function(){
        var layer_title=$('.layui-layer-title').text();

        var cuid=$("input[name='cuid']").val();
        var cuname1=$("input[name='cuname1']").val();
        var cusex=$.trim($("select[name='cusex']").val());
        var srrq=$("input[name='srrq']").val();
        var cumomile=$("input[name='cumomile']").val();
        var cutel=$("input[name='cutel']").val();
        var cuadd=$("input[name='cuadd']").val();
        var cupost=$("input[name='cupost']").val();
        var Mail=$("input[name='Mail']").val();
        var cudiscount=$("input[name='cudiscount']").val();

        if(isNaN(cudiscount)||cudiscount<0||cudiscount>1){
            layer.msg("请填写折扣值0~1之间");
            return;
        }
        //可透支 overdraft
        var overdraft= $("input[name='overdraft']").is(':checked');
        if(overdraft){overdraft="Y"}else{overdraft="N"};
        //可积分 sfjf
        var sfjf= $("input[name='sfjf']").is(':checked');
        if(sfjf){sfjf="Y"}else{sfjf="N"};



        if(layer_title=="新增"){
            $.ajax({
                type: "post",
                url:G_url+'cacu/add'+'?sign='+sign,
                data:"cuid="+cuid+"&cuname1="+cuname1+"&cusex="+cusex+"&cumomile="+cumomile+"&srrq="+srrq+"&cutel="+cutel+"&cuadd="+cuadd+"&cudiscount="+cudiscount +"&overdraft="+overdraft+"&sfjf="+sfjf,

                dataType: "json",
                success: function (result){
                    if (result.ok){
                        f_sheard();
                        layer.msg(result.msg);
                    } else {
                        layer.msg(result.msg);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                }
            });
            layer.closeAll();

        }else if(layer_title=="修改"){
            $.ajax({
                type: "post",
                url:G_url+'cacu/save'+'?'+'sign='+sign,
                data:"cuid="+cuid+"&cuname1="+cuname1+"&cusex="+cusex+"&cumomile="+cumomile+"&srrq="+srrq+"&cutel="+cutel+"&cuadd="+cuadd+"&cudiscount="+cudiscount +"&overdraft="+overdraft+"&sfjf="+sfjf,
                dataType: "json",
                success: function (result){
                    if (result.ok){
                        f_sheard();
                        layer.msg(result.msg);
                    } else {
                        layer.msg(result.msg);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                }
            });
            layer.closeAll();
        }


    });

    <!--保存操作-->

    <!--修改信息-->
    function actionFormatter(value, row, index){
        return "<a class='label label-warning'  href='javascript:void(0)' onclick='open_edit("+JSON.stringify(row)+","+index+");'>"+value+"</a>";
    }
    function open_edit(r,i){

        if (r){
            $("input[name='bh']").attr("disabled",true);
            $("#open_edit").show();
            rid= r.rid;

            index=i;
            console.log(r);

            var cuid=$("input[name='cuid']").val(r.cuid);
            var cuname1=$("input[name='cuname1']").val(r.cuname1);
            var cusex=$("select[name='cusex']").val(r.cusex);
            var srrq=$("input[name='srrq']").val(r.srrq);
            var cumomile=$("input[name='cumomile']").val(r.cumomile);
            var cutel=$("input[name='cutel']").val(r.cutel);
            var cuadd=$("input[name='cuadd']").val(r.cuadd);
            var cupost=$("input[name='cupost']").val(r.cupost);
            var Mail=$("input[name='Mail']").val(r.Mail);
            var cudiscount=$("input[name='cudiscount']").val(r.cudiscount);

            // $("input[name='overdraft']").prop("checked",function(){
            //      return true;
            // });

            if(r.overdraft=="Y"){
                $("input[name='overdraft']").iCheck('check');
            }else{
                $("input[name='overdraft']").iCheck('uncheck');
            }
            if(r.sfjf=="Y"){
                $("input[name='sfjf']").iCheck('check');
            }else{
                $("input[name='sfjf']").iCheck('uncheck');
            }





            layer.open({
                title: "修改",
                type: 1,
                offset: 'rb',
                area: ['40%', '100%'], //宽高
                shadeClose: true,
                content: $('#edit_from')
            });
            //  $("input[name='overdraft']").prop('checked',true);   



        }
    };
    <!--修改信息-->

    <!--本地搜索-->
    $("#search").on("click",function(){
        alert("搜索");
    });

    $('#searchtext').bind('keypress',function(event){
        if(event.keyCode == "13") {
            do_search();
        }
    });

    function do_search(){
        var gjc=$('#searchtext').val(); //搜索关键词
        if(gjc==""){
            console.log(mydata);
            $table.bootstrapTable('load', mydata);
        }else{
            var newdata=[];
            for(var i=0;i<mydata.data.length;i++){
                str=transform(mydata.data[i]).join(',');
                row=str.indexOf(gjc);
                if(row>=0){
                    newdata.push(mydata.data[i]);
                }
            }
            $table.bootstrapTable('load', newdata);
        }
    }
    function transform(obj){
        var arr = [];
        for(var item in obj){
            arr.push(obj[item]);
        }
        return arr;
    }
    <!--本地搜索-->









</script>
</body>
</html>
